﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MixScript.BLL.FI;
using System.Data;
using System.Xml;

namespace MixScriptWeb.Accounting
{
    public partial class fBeginingGL : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        private void LoadData()
        {
            BeginningLedger ldgr = new BeginningLedger();
            DataTable dt = new DataTable();
            if (ldgr.getLedger(ref dt))
            { }
            else
            { }
            gvBeginingJournal.DataSource = dt;
            gvBeginingJournal.DataBind();

        }
        protected void gvdetail_RowDataBound(Object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TextBox txt1 = new TextBox();
                TextBox txt2 = new TextBox();
                txt1 = (TextBox)e.Row.Cells[3].FindControl("txtDebit");
                txt2 = (TextBox)e.Row.Cells[3].FindControl("txtCredit");
                if (e.Row.Cells[0].Text.Contains("."))
                {
                    if (e.Row.Cells[4].Text == "2" || e.Row.Cells[4].Text == "3" || e.Row.Cells[4].Text == "4"
                                        || e.Row.Cells[4].Text == "5" || e.Row.Cells[4].Text == "6")
                    {
                        txt1.Enabled = false;
                        txt1.BackColor = System.Drawing.Color.Gray;
                        txt2.Enabled = false;
                        txt2.BackColor = System.Drawing.Color.Gray;
                    }
                    else
                    {
                        txt1.Enabled = true;
                        txt2.Enabled = true;
                    }
                }
                else
                {
                    txt1.Enabled = true;
                    txt2.Enabled = true;
                }

            }

        }
        protected void btnReset_click(object sender, EventArgs e)
        {

            Response.Redirect("~/Accounting/fBeginingGL.aspx");
        }
        protected void btnSave_click(object sender, EventArgs e)
        {

            TextBox txt = new TextBox();

            for (int i = 0; i < gvBeginingJournal.Rows.Count - 1; i++)
            {

                if (gvBeginingJournal.Rows[i].Cells[3].Text == "D")
                    txt = (TextBox)gvBeginingJournal.Rows[i].FindControl("txtDebit");
                else
                    txt = (TextBox)gvBeginingJournal.Rows[i].FindControl("txtCredit");


                BeginningLedger bl = new BeginningLedger();
                bl.SaveLedger(gvBeginingJournal.Rows[i].Cells[0].Text,
                    "",
                    gvBeginingJournal.Rows[i].Cells[4].Text,
                    gvBeginingJournal.Rows[i].Cells[3].Text,
                    txt.Text);

            }
        }
    }
}